
var vm = new Vue({
    el : "#inventory",
    data : {
        record:{},
        sels:[],
        table: null,
        pid : '',
        qty : '',
        kcqty : '',
        locatorCode :'',
        inventoryList : []
    },
    methods: {
        submit : function(){
            var _self = this;
            qty =document.getElementById("num").value;
            // qty = $("#num").text();
            var data ={
                locatorCode :locatorCode ,pid : pid, qty : qty, kcqty : kcqty
            };
            var inventoryList = [];
            _self.$nextTick(function() {
                _self.$http.post(host +"inventory/submit",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.vueAlert("操作成功！");
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },
        serch : function(){
            var _self = this;
            locatorCode = document.getElementById("id").value;   //货位
            if(locatorCode == null || locatorCode.trim() ==''){
                _self.vueAlert("请输入货位号");
            };
            var data ={
                value : locatorCode
            };
            _self.$nextTick(function() {
                _self.$http.post(host +"inventory/serch",data,{emulateJSON: true}).then(function(res){
                    if(res.ok){
                        _self.inventoryList = res.body.rows;
                        if(_self.inventoryList == null || _self.inventoryList.length == 0){
                            _self.vueAlert(res.body.msg);
                            return;
                        }
                        $("#productName option").remove();
                        inventoryList =  _self.inventoryList;
                        for (let v of inventoryList) {
                            var option = document.createElement("option");
                            $(option).val(v.PID);
                            $(option).text(v.PRODUCTNAME);
                            $("#productName").append(option);
                        }
                        // document.getElementById("qty").innerText = "盘点数量：" + nvl(inventoryList[0].QTY);
                        // document.getElementById("uname").innerText = "规格型号：" + nvl(inventoryList[0].UNAME);
                        // document.getElementById("color").innerText = "颜色：" + nvl(inventoryList[0].COLOR);
                        document.getElementById("kcqty").innerText = "库存：" + nvl(inventoryList[0].KCQTY);
                        layui.use(['form'], function(){
                            var form = layui.form;
                            form.render();
                            form.on('select(productName)', function(data){
                                console.log(data.value); //得到被选中的值
                                pid = data.value;
                                for (let list of inventoryList) {
                                    if(list.PID == data.value){
                                        // document.getElementById("uname").innerText = "规格型号：" + list.UNAME;
                                        // document.getElementById("color").innerText = "颜色：" + list.COLOR;
                                        document.getElementById("kcqty").innerText = "库存：" + list.KCQTY;
                                        kcqty = list.KCQTY;
                                    }
                                }

                            });
                        });
                    }else{
                        layer.msg("操作失败");
                    }
                });
            });
        },

        vueAlert:function(msg){
            layui.use(['form'], function(){
                var layer = layui.layer;
                layer.msg(msg,{icon:6,time:2000});
            });
        }

    }
});